const fs = require('fs');
const path = require('path')

const filePath = path.resolve(__dirname, './logUserMsg.json')

//  日记存储 ， 传结果
function logmsgSubmit(detail) {
    return new Promise((resolve, reject) => {
        let dataBuffer = fs.readFileSync(filePath)
        let dataObj = JSON.parse(dataBuffer.toString())
        let time = new Date().getTime()
        let newLogmsg = {
            time,
            ...detail
        }
        dataObj.push(newLogmsg)
        fs.writeFileSync(filePath, JSON.stringify(dataObj))
        resolve(`logmsgSubmit success--${__dirname}`)
        
    })
}
logmsgSubmit()